package com.jjh.controller;

import com.jjh.consts.Result;
import com.jjh.pojo.Category;
import com.jjh.service.CateGoryService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/category")
public class CateGoryController {

    @Resource
    private CateGoryService cateGoryService;

    /**
     * 条件分页查询
     * @param page
     * @param size
     * @param map
     * @return
     */
    @PostMapping("/page/{page}/{size}")
    public Result page(@PathVariable("page")Integer page,
                       @PathVariable("size")Integer size,
                       @RequestBody Map<String,Object> map){

        return cateGoryService.page(page,size,map);
    }

    @PostMapping("/add")
    public Result addOne(@RequestBody Category category){
        //System.out.println(category);
        return cateGoryService.addOne(category);
    }

    @PutMapping("/update")
    public Result updateOne(@RequestBody Category category){
        return cateGoryService.updateOne(category);
    }

    @PostMapping("/delete")
    public Result deleteUsers(@RequestBody Map<String, List<Integer>> map) throws SQLIntegrityConstraintViolationException {
        List<Integer> ids = map.get("ids");
        return cateGoryService.deleteByIds(ids);
    }

    /**
     * 获取所有的菜品分类
     * @return
     */
    @GetMapping("/dishcate")
    public Result getDishCates(){
        return cateGoryService.getDishCates();
    }
    /**
     * 获取所有的套餐分类
     * @return
     */
    @GetMapping("/taocancate")
    public Result getTaoCanCates(){
        return cateGoryService.getTaoCanCates();
    }



}
